home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / libexpect.z / libexpect
Encoding:
Text File  |  1998-10-30  |  43.4 KB  |  727 lines

  1.  
  2.  
  3.  
  4. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      expect - C functions for programmed dialogue with interactive programs
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee eeeexxxxppppeeeecccctttt____ttttccccllll....hhhh
  13.      EEEExxxxpppp____IIIInnnniiiitttt((((iiiinnnntttteeeerrrrpppp))));;;;
  14.  
  15.      cccccccc ffffiiiilllleeeessss............ ----lllleeeexxxxppppeeeecccctttt ----llllttttccccllll ----llllmmmm
  16.  
  17.  
  18. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  19.      This library contains functions that allow Expect to be used as a Tcl
  20.      extension or to be used directly from C or C++ (without Tcl).  Adding
  21.      Expect as a Tcl extension is very short and simple, so that will be
  22.      covered first.
  23.  
  24.      The Exp_Init function adds expect commands to the named interpreter.  It
  25.      avoids overwriting commands that already exist, however aliases beginning
  26.      with "exp_" are always created for expect commands.  So for example,
  27.      "send" can be used as "exp_send".
  28.  
  29.      Generally, you should only call Expect commands via Tcl_Eval.  Certain
  30.      auxiliary functions may be called directly.  They are summarized below.
  31.      They may be useful in constructing your own main.  Look at the file
  32.      exp_main_exp.c in the Expect distribution as a prototype main.  Another
  33.      prototype is tclAppInit.c in the Tcl source distribution.  A prototype
  34.      for working with Tk is in exp_main_tk.c in the Expect distribution.
  35.  
  36.      int exp_cmdlinecmds;
  37.      int exp_interactive;
  38.      FILE *exp_cmdfile;
  39.      char *exp_cmdfilename;
  40.      int exp_tcl_debugger_available;
  41.  
  42.      void exp_parse_argv(Tcl_Interp *,int argc,char **argv);
  43.      int  exp_interpreter(Tcl_Interp *);
  44.      void exp_interpret_cmdfile(Tcl_Interp *,FILE *);
  45.      void exp_interpret_cmdfilename(Tcl_Interp *,char *);
  46.      void exp_interpret_rcfiles(Tcl_Interp *,int my_rc,int sys_rc);
  47.      char *    exp_cook(char *s,int *len);
  48.      void (*exp_app_exit)EXP_PROTO((Tcl_Interp *);
  49.      void exp_exit(Tcl_Interp *,int status);
  50.      void exp_exit_handlers(Tcl_Interp *);
  51.      void exp_error(Tcl_Interp,char *,...);
  52.  
  53.      eeeexxxxpppp____ccccmmmmddddlllliiiinnnneeeeccccmmmmddddssss is 1 if Expect has been invoked with commands on the
  54.      program command-line (using "-c" for example).  eeeexxxxpppp____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee is 1 if
  55.      Expect has been invoked with the -i flag or if no commands or script is
  56.      being invoked.  eeeexxxxpppp____ccccmmmmddddffffiiiilllleeee is a stream from which Expect will read
  57.      commands.  eeeexxxxpppp____ccccmmmmddddffffiiiilllleeeennnnaaaammmmeeee is the name of a file which Expect will open
  58.      and read commands from.  eeeexxxxpppp____ttttccccllll____ddddeeeebbbbuuuuggggggggeeeerrrr____aaaavvvvaaaaiiiillllaaaabbbblllleeee is 1 if the debugger
  59.      has been armed.
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      eeeexxxxpppp____ppppaaaarrrrsssseeee____aaaarrrrggggvvvv reads the representation of the command line.  Based on
  75.      what is found, any of the other variables listed here are initialized
  76.      appropriately.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttteeeerrrr interactively prompts the user for
  77.      commands and evaluates them.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____ccccmmmmddddffffiiiilllleeee reads the given
  78.      stream and evaluates any commands found.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____ccccmmmmddddffffiiiilllleeeennnnaaaammmmeeee opens
  79.      the named file and evaluates any commands found.  eeeexxxxpppp____iiiinnnntttteeeerrrrpppprrrreeeetttt____rrrrccccffffiiiilllleeeessss
  80.      reads and evalutes the .rc files.  If my_rc is zero, then ~/.expectrc is
  81.      skipped.  If sys_rc is zero, then the system-wide expectrc file is
  82.      skipped.  eeeexxxxpppp____ccccooooooookkkk returns a static buffer containing the argument
  83.      reproduced with newlines replaced by carriage-return linefeed sequences.
  84.      The primary purpose of this is to allow messages to be produced without
  85.      worrying about whether the terminal is in raw mode or cooked mode.  If
  86.      length is zero, it is computed via strlen.  eeeexxxxpppp____eeeerrrrrrrroooorrrr iiiissss aaaa pppprrrriiiinnnnttttffff----lllliiiikkkkeeee
  87.      ffffuuuunnnnccccttttiiiioooonnnn tttthhhhaaaatttt to interp->result.
  88.  
  89. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  90.      ####iiiinnnncccclllluuuuddddeeee <<<<eeeexxxxppppeeeecccctttt....hhhh>>>>
  91.  
  92.      iiiinnnntttt
  93.      eeeexxxxpppp____ssssppppaaaawwwwnnnnllll((((ffffiiiilllleeee,,,, aaaarrrrgggg0000 [[[[,,,, aaaarrrrgggg1111,,,, ............,,,, aaaarrrrggggnnnn]]]] ((((cccchhhhaaaarrrr ****))))0000))));;;;
  94.      cccchhhhaaaarrrr ****ffffiiiilllleeee;;;;
  95.      cccchhhhaaaarrrr ****aaaarrrrgggg0000,,,, ****aaaarrrrgggg1111,,,, ............ ****aaaarrrrggggnnnn;;;;
  96.  
  97.      iiiinnnntttt
  98.      eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv((((ffffiiiilllleeee,,,,aaaarrrrggggvvvv))));;;;
  99.      cccchhhhaaaarrrr ****ffffiiiilllleeee,,,, ****aaaarrrrggggvvvv[[[[ ]]]];;;;
  100.  
  101.      iiiinnnntttt
  102.      eeeexxxxpppp____ssssppppaaaawwwwnnnnffffdddd((((ffffdddd))));;;;
  103.      iiiinnnntttt ffffdddd;;;;
  104.  
  105.      FFFFIIIILLLLEEEE ****
  106.      eeeexxxxpppp____ppppooooppppeeeennnn((((ccccoooommmmmmmmaaaannnndddd))));;;;
  107.      cccchhhhaaaarrrr ****ccccoooommmmmmmmaaaannnndddd;;;;
  108.  
  109.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ppppiiiidddd;;;;
  110.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttttttyyyyiiiinnnniiiitttt;;;;
  111.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttttttyyyyccccooooppppyyyy;;;;
  112.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ccccoooonnnnssssoooolllleeee;;;;
  113.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____ssssttttttttyyyy____iiiinnnniiiitttt;;;;
  114.      eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd ((((****eeeexxxxpppp____cccclllloooosssseeee____iiiinnnn____cccchhhhiiiilllldddd))))(((())));;;;
  115.      eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd ((((****eeeexxxxpppp____cccchhhhiiiilllldddd____eeeexxxxeeeecccc____pppprrrreeeelllluuuuddddeeee))))(((())));;;;
  116.      eeeexxxxtttteeeerrrrnnnn vvvvooooiiiidddd eeeexxxxpppp____cccclllloooosssseeee____ttttccccllll____ffffiiiilllleeeessss(((())));;;;
  117.  
  118.      cccccccc ffffiiiilllleeeessss............ ----lllleeeexxxxppppeeeecccctttt ----llllttttccccllll ----llllmmmm
  119.  
  120.  
  121. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  122.      eeeexxxxpppp____ssssppppaaaawwwwnnnnllll and eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv fork a new process so that its stdin, stdout,
  123.      and stderr can be written and read by the current process.  _f_i_l_e is the
  124.      name of a file to be executed.  The _a_r_g pointers are null-terminated
  125.      strings.  Following the style of execve(), _a_r_g_0 (or _a_r_g_v[_0]) is
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140.      customarily a duplicate of the name of the file.
  141.  
  142.      Four interfaces are available, eeeexxxxpppp____ssssppppaaaawwwwnnnnllll is useful when the number of
  143.      arguments is known at compile time.  eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv is useful when the number
  144.      of arguments is not known at compile time.  eeeexxxxpppp____ssssppppaaaawwwwnnnnffffdddd is useful when an
  145.      open file descriptor is already available as a source.  eeeexxxxpppp____ppppooooppppeeeennnn is
  146.      explained later on.
  147.  
  148.      If the process is successfully created, a file descriptor is returned
  149.      which corresponds to the process's stdin, stdout and stderr.  A stream
  150.      may be associated with the file descriptor by using fdopen().  (This
  151.      should almost certainly be followed by setbuf() to unbuffer the I/O.)
  152.  
  153.      Closing the file descriptor will typically be detected by the process as
  154.      an EOF.  Once such a process exits, it should be waited upon (via wait)
  155.      in order to free up the kernel process slot.  (Some systems allow you to
  156.      avoid this if you ignore the SIGCHLD signal).
  157.  
  158.      eeeexxxxpppp____ppppooooppppeeeennnn is yet another interface, styled after popen().  It takes a
  159.      Bourne shell command line, and returns a stream that corresponds to the
  160.      process's stdin, stdout and stderr.  The actual implementation of
  161.      eeeexxxxpppp____ppppooooppppeeeennnn below demonstrates eeeexxxxpppp____ssssppppaaaawwwwnnnnllll.
  162.  
  163.      FILE *
  164.      exp_popen(program)
  165.      char *program;
  166.      {
  167.           FILE *fp;
  168.           int ec;
  169.  
  170.           if (0 > (ec = exp_spawnl("sh","sh","-c",program,(char *)0)))
  171.                return(0);
  172.           if (NULL == (fp = fdopen(ec,"r+")) return(0);
  173.           setbuf(fp,(char *)0);
  174.           return(fp);
  175.      }
  176.  
  177.      After a process is started, the variable eeeexxxxpppp____ppppiiiidddd is set to the process-id
  178.      of the new process.  The variable eeeexxxxpppp____ppppttttyyyy____ssssllllaaaavvvveeee____nnnnaaaammmmeeee is set to the name
  179.      of the slave side of the pty.
  180.  
  181.      The spawn functions uses a pty to communicate with the process.  By
  182.      default, the pty is initialized the same way as the user's tty (if
  183.      possible, i.e., if the environment has a controlling terminal.)  This
  184.      initialization can be skipped by setting exp_ttycopy to 0.
  185.  
  186.      The pty is further initialized to some system wide defaults if
  187.      exp_ttyinit is non-zero.  The default is generally comparable to "stty
  188.      sane".
  189.  
  190.      The tty setting can be further modified by setting the variable
  191.      eeeexxxxpppp____ssssttttttttyyyy____iiiinnnniiiitttt.  This variable is interpreted in the style of stty
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  203.  
  204.  
  205.  
  206.      arguments.  For example, exp_stty_init = "sane"; repeats the default
  207.      initialization.
  208.  
  209.      On some systems, it is possible to redirect console output to ptys.  If
  210.      this is supported, you can force the next spawn to obtain the console
  211.      output by setting the variable eeeexxxxpppp____ccccoooonnnnssssoooolllleeee to 1.
  212.  
  213.      Between the time a process is started and the new program is given
  214.      control, the spawn functions can clean up the environment by closing file
  215.      descriptors.  By default, the only file descriptors closed ones internal
  216.      to Expect and any marked "close-on-exec".
  217.  
  218.      If needed, you can close additional file descriptors by creating an
  219.      appropriate function and assigning it to exp_close_in_child.  The
  220.      function will be called after the fork and before the exec.  (This also
  221.      modifies the behavior of the spawn command in Expect.)
  222.  
  223.      If you are also using Tcl, it may be convenient to use the function
  224.      exp_close_tcl_files which closes all files between the default standard
  225.      file descriptors and the highest descriptor known to Tcl.  (Expect does
  226.      this.)
  227.  
  228.      The function exp_child_exec_prelude is the last function called prior to
  229.      the actual exec in the child.  You can redefine this for effects such as
  230.      manipulating the uid or the signals.
  231.  
  232.  
  233. IIIIFFFF YYYYOOOOUUUU WWWWAAAANNNNTTTT TTTTOOOO AAAALLLLLLLLOOOOCCCCAAAATTTTEEEE YYYYOOOOUUUURRRR OOOOWWWWNNNN PPPPTTTTYYYY
  234.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____aaaauuuuttttooooaaaallllllllooooccccppppttttyyyy;;;;
  235.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ppppttttyyyy[[[[2222]]]];;;;
  236.  
  237.      The spawn functions use a pty to communicate with the process.  By
  238.      default, a pty is automatically allocated each time a process is spawned.
  239.      If you want to allocate ptys yourself, before calling one of the spawn
  240.      functions, set eeeexxxxpppp____aaaauuuuttttooooaaaallllllllooooccccppppttttyyyy to 0, eeeexxxxpppp____ppppttttyyyy[[[[0000]]]] to the master pty file
  241.      descriptor and eeeexxxxpppp____ppppttttyyyy[[[[1111]]]] to the slave pty file descriptor.  The expect
  242.      library will not do any pty initializations (e.g., exp_stty_init will not
  243.      be used).  The slave pty file descriptor will be automatically closed
  244.      when the process is spawned.  After the process is started, all further
  245.      communication takes place with the master pty file descriptor.
  246.  
  247.      eeeexxxxpppp____ssssppppaaaawwwwnnnnllll and eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv duplicate the shell's actions in searching for
  248.      an executable file in a list of directories.  The directory list is
  249.      obtained from the environment.
  250.  
  251. EEEEXXXXPPPPEEEECCCCTTTT PPPPRRRROOOOCCCCEEEESSSSSSSSIIIINNNNGGGG
  252.      While it is possible to use read() to read information from a process
  253.      spawned by eeeexxxxpppp____ssssppppaaaawwwwnnnnllll or eeeexxxxpppp____ssssppppaaaawwwwnnnnvvvv, more convenient functions are
  254.      provided.  They are as follows:
  255.  
  256.      iiiinnnntttt
  257.      eeeexxxxpppp____eeeexxxxppppeeeeccccttttllll((((ffffdddd,,,,ttttyyyyppppeeee1111,,,,ppppaaaatttttttteeeerrrrnnnn1111,,,,[[[[rrrreeee1111,,,,]]]],,,,vvvvaaaalllluuuueeee1111,,,,ttttyyyyppppeeee2222,,,,............,,,,eeeexxxxpppp____eeeennnndddd))));;;;
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  269.  
  270.  
  271.  
  272.      iiiinnnntttt ffffdddd;;;;
  273.      eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  274.      cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn1111,,,, ****ppppaaaatttttttteeeerrrrnnnn2222,,,, ............;;;;
  275.      rrrreeeeggggeeeexxxxpppp ****rrrreeee1111,,,, ****rrrreeee2222,,,, ............;;;;
  276.      iiiinnnntttt vvvvaaaalllluuuueeee1111,,,, vvvvaaaalllluuuueeee2222,,,, ............;;;;
  277.  
  278.      iiiinnnntttt
  279.      eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttllll((((ffffpppp,,,,ttttyyyyppppeeee1111,,,,ppppaaaatttttttteeeerrrrnnnn1111,,,,[[[[rrrreeee1111,,,,]]]]vvvvaaaalllluuuueeee1111,,,,ttttyyyyppppeeee2222,,,,............,,,,eeeexxxxpppp____eeeennnndddd))));;;;
  280.      FFFFIIIILLLLEEEE ****ffffpppp;;;;
  281.      eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  282.      cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn1111,,,, ****ppppaaaatttttttteeeerrrrnnnn2222,,,, ............;;;;
  283.      rrrreeeeggggeeeexxxxpppp ****rrrreeee1111,,,, ****rrrreeee2222,,,, ............;;;;
  284.      iiiinnnntttt vvvvaaaalllluuuueeee1111,,,, vvvvaaaalllluuuueeee2222,,,, ............;;;;
  285.  
  286.      eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee {{{{
  287.           eeeexxxxpppp____eeeennnndddd,,,,
  288.           eeeexxxxpppp____gggglllloooobbbb,,,,
  289.           eeeexxxxpppp____eeeexxxxaaaacccctttt,,,,
  290.           eeeexxxxpppp____rrrreeeeggggeeeexxxxpppp,,,,
  291.           eeeexxxxpppp____ccccoooommmmppppiiiilllleeeedddd,,,,
  292.           eeeexxxxpppp____nnnnuuuullllllll,,,,
  293.      }}}};;;;
  294.  
  295.      ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee {{{{
  296.           cccchhhhaaaarrrr ****ppppaaaatttttttteeeerrrrnnnn;;;;
  297.           rrrreeeeggggeeeexxxxpppp ****rrrreeee;;;;
  298.           eeeennnnuuuummmm eeeexxxxpppp____ttttyyyyppppeeee ttttyyyyppppeeee;;;;
  299.           iiiinnnntttt vvvvaaaalllluuuueeee;;;;
  300.      }}}};;;;
  301.  
  302.      iiiinnnntttt
  303.      eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv((((ffffdddd,,,,ccccaaaasssseeeessss))));;;;
  304.      iiiinnnntttt ffffdddd;;;;
  305.      ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee ****ccccaaaasssseeeessss;;;;
  306.  
  307.      iiiinnnntttt
  308.      eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv((((ffffpppp,,,,ccccaaaasssseeeessss))));;;;
  309.      FFFFIIIILLLLEEEE ****ffffpppp;;;;
  310.      ssssttttrrrruuuucccctttt eeeexxxxpppp____ccccaaaasssseeee ****ccccaaaasssseeeessss;;;;
  311.  
  312.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ttttiiiimmmmeeeeoooouuuutttt;;;;
  313.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____mmmmaaaattttcccchhhh;;;;
  314.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____mmmmaaaattttcccchhhh____eeeennnndddd;;;;
  315.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr;;;;
  316.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr____eeeennnndddd;;;;
  317.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____mmmmaaaattttcccchhhh____mmmmaaaaxxxx;;;;
  318.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ffffuuuullllllll____bbbbuuuuffffffffeeeerrrr;;;;
  319.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____rrrreeeemmmmoooovvvveeee____nnnnuuuullllllllssss;;;;
  320.  
  321.      The functions wait until the output from a process matches one of the
  322.      patterns, a specified time period has passed, or an EOF is seen.
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  335.  
  336.  
  337.  
  338.      The first argument to each function is either a file descriptor or a
  339.      stream.  Successive sets of arguments describe patterns and associated
  340.      integer values to return when the pattern matches.
  341.  
  342.      The type argument is one of four values.  exp_end indicates that no more
  343.      patterns appear.  exp_glob indicates that the pattern is a glob-style
  344.      string pattern.  exp_exact indicates that the pattern is an exact string.
  345.      exp_regexp indicates that the pattern is a regexp-style string pattern.
  346.      exp_compiled indicates that the pattern is a regexp-style string pattern,
  347.      and that its compiled form is also provided.  exp_null indicates that the
  348.      pattern is a null (for debugging purposes, a string pattern must also
  349.      follow - for debugging purposes).
  350.  
  351.      If the compiled form is not provided with the functions eeeexxxxpppp____eeeexxxxppppeeeeccccttttllll and
  352.      eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttllll, , any pattern compilation done internally is thrown away
  353.      after the function returns.  The functions eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv and eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv
  354.      will automatically compile patterns and will not throw them away.
  355.      Instead, they must be discarded by the user, by calling free on each
  356.      pattern.  It is only necessary to discard them, the last time the cases
  357.      are used.
  358.  
  359.      Regexp subpatterns matched are stored in the compiled regexp.  Assuming
  360.      "re" contains a compiled regexp, the matched string can be found in re-
  361.      >startp[0].  The match substrings (according to the parentheses) in the
  362.      original pattern can be found in re->startp[1], re->startp[2], and so on,
  363.      up to re->startp[9].  The corresponding strings ends are re->endp[x]
  364.      where x is that same index as for the string start.
  365.  
  366.      The type exp_null matches if a null appears in the input.  The variable
  367.      exp_remove_nulls must be set to 0 to prevent nulls from being
  368.      automatically stripped.  By default, exp_remove_nulls is set to 1 and
  369.      nulls are automatically stripped.
  370.  
  371.      eeeexxxxpppp____eeeexxxxppppeeeeccccttttvvvv and eeeexxxxpppp____ffffeeeexxxxppppeeeeccccttttvvvv are useful when the number of patterns is
  372.      not known in advance.  In this case, the sets are provided in an array.
  373.      The end of the array is denoted by a struct exp_case with type exp_end.
  374.      For the rest of this discussion, these functions will be referred to
  375.      generically as _e_x_p_e_c_t.
  376.  
  377.      If a pattern matches, then the corresponding integer value is returned.
  378.      Values need not be unique, however they should be positive to avoid being
  379.      mistaken for EXP_EOF, EXP_TIMEOUT, or EXP_FULLBUFFER.  Upon EOF or
  380.      timeout, the value EEEEXXXXPPPP____EEEEOOOOFFFF or EEEEXXXXPPPP____TTTTIIIIMMMMEEEEOOOOUUUUTTTT is returned.  The default
  381.      timeout period is 10 seconds but may be changed by setting the variable
  382.      eeeexxxxpppp____ttttiiiimmmmeeeeoooouuuutttt.  A value of -1 disables a timeout from occurring.  A value
  383.      of 0 causes the expect function to return immediately (i.e., poll) after
  384.      one read().  However it must be preceded by a function such as select,
  385.      poll, or an event manager callback to guarantee that there is data to be
  386.      read.
  387.  
  388.      If the variable exp_full_buffer is 1, then EXP_FULLBUFFER is returned if
  389.      exp_buffer fills with no pattern having matched.
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  401.  
  402.  
  403.  
  404.      When the expect function returns, eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr points to the buffer of
  405.      characters that was being considered for matching.  eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr____eeeennnndddd ppppooooiiiinnnnttttssss
  406.      ttttoooo oooonnnneeee ppppaaaasssstttt tttthhhheeee If a match occurred, eeeexxxxpppp____mmmmaaaattttcccchhhh points into eeeexxxxpppp____bbbbuuuuffffffffeeeerrrr
  407.      where the match began.  eeeexxxxpppp____mmmmaaaattttcccchhhh____eeeennnndddd points to one character past where
  408.      the match ended.
  409.  
  410.      Each time new input arrives, it is compared to each pattern in the order
  411.      they are listed.  Thus, you may test for absence of a match by making the
  412.      last pattern something guaranteed to appear, such as a prompt.  In
  413.      situations where there is no prompt, you must check for EEEEXXXXPPPP____TTTTIIIIMMMMEEEEOOOOUUUUTTTT (just
  414.      like you would if you were interacting manually).  More philosophy and
  415.      strategies on specifying eeeexxxxppppeeeecccctttt patterns can be found in the
  416.      documentation on the eeeexxxxppppeeeecccctttt program, itself.  See SEE ALSO below.
  417.  
  418.      Patterns are the usual C-shell-style regular expressions.  For example,
  419.      the following fragment looks for a successful login, such as from a
  420.      telnet dialogue.
  421.  
  422.           switch (exp_expectl(
  423.                exp_glob,"connected",CONN,
  424.                exp_glob,"busy",BUSY,
  425.                exp_glob,"failed",ABORT,
  426.                exp_glob,"invalid password",ABORT,
  427.                exp_end)) {
  428.           case CONN:     /* logged in successfully */
  429.                break;
  430.           case BUSY:     /* couldn't log in at the moment */
  431.                break;
  432.           case EXP_TIMEOUT:
  433.           case ABORT:    /* can't log in at any moment! */
  434.                break;
  435.           default: /* problem with expect */
  436.           }
  437.  
  438.      Asterisks (as in the example above) are a useful shorthand for omitting
  439.      line-termination characters and other detail.  Patterns must match the
  440.      entire output of the current process (since the previous read on the
  441.      descriptor or stream). More than 2000 bytes of output can force earlier
  442.      bytes to be "forgotten".  This may be changed by setting the variable
  443.      eeeexxxxpppp____mmmmaaaattttcccchhhh____mmmmaaaaxxxx.  Note that excessively large values can slow down the
  444.      pattern matcher.
  445.  
  446. RRRRUUUUNNNNNNNNIIIINNNNGGGG IIIINNNN TTTTHHHHEEEE BBBBAAAACCCCKKKKGGGGRRRROOOOUUUUNNNNDDDD
  447.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____ddddiiiissssccccoooonnnnnnnneeeecccctttteeeedddd;;;;
  448.      iiiinnnntttt eeeexxxxpppp____ddddiiiissssccccoooonnnnnnnneeeecccctttt(((())));;;;
  449.  
  450.      It is possible to move a process into the background after it has begun
  451.      running.  A typical use for this is to read passwords and then go into
  452.      the background to sleep before using the passwords to do real work.
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  467.  
  468.  
  469.  
  470.      To move a process into the background, fork, call exp_disconnect() in the
  471.      child process and exit() in the parent process.  This disassociates your
  472.      process from the controlling terminal.  If you wish to move a process
  473.      into the background in a different way, you must set the variable
  474.      exp_disconnected to 1.  This allows processes spawned after this point to
  475.      be started correctly.
  476.  
  477. MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEEXXXXIIIINNNNGGGG
  478.      By default, the expect functions block inside of a read on a single file
  479.      descriptor.  If you want to wait on patterns from multiple file
  480.      descriptors, use select, poll, or an event manager.  They will tell you
  481.      what file descriptor is ready to read.
  482.  
  483.      When a file descriptor is ready to read, you can use the expect functions
  484.      to do one and only read by setting timeout to 0.
  485.  
  486. SSSSLLLLAAAAVVVVEEEE CCCCOOOONNNNTTTTRRRROOOOLLLL
  487.      vvvvooooiiiidddd
  488.      eeeexxxxpppp____ssssllllaaaavvvveeee____ccccoooonnnnttttrrrroooollll((((ffffdddd,,,,eeeennnnaaaabbbblllleeee))))
  489.      iiiinnnntttt ffffdddd;;;;
  490.      iiiinnnntttt eeeennnnaaaabbbblllleeee;;;;
  491.  
  492.  
  493.      Pty trapping is normally done automatically by the expect functions.
  494.      However, if you want to issue an ioctl, for example, directly on the
  495.      slave device, you should temporary disable trapping.
  496.  
  497.      Pty trapping can be controlled with exp_slave_control.  The first
  498.      argument is the file descriptor corresponding to the spawned process.
  499.      The second argument is a 0 if trapping is to be disabled and 1 if it is
  500.      to be enabled.
  501.  
  502.  
  503. EEEERRRRRRRROOOORRRRSSSS
  504.      All functions indicate errors by returning -1 and setting errno.
  505.  
  506.      Errors that occur after the spawn functions fork (e.g., attempting to
  507.      spawn a non-existent program) are written to the process's stderr, and
  508.      will be read by the first eeeexxxxppppeeeecccctttt.
  509.  
  510. SSSSIIIIGGGGNNNNAAAALLLLSSSS
  511.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____rrrreeeeaaaaddddiiiinnnngggg;;;;
  512.      eeeexxxxtttteeeerrrrnnnn jjjjmmmmpppp____bbbbuuuuffff eeeexxxxpppp____rrrreeeeaaaaddddeeeennnnvvvv;;;;
  513.  
  514.      eeeexxxxppppeeeecccctttt uses alarm() to timeout, thus if you generate alarms during
  515.      eeeexxxxppppeeeecccctttt, it will timeout prematurely.
  516.  
  517.      Internally, eeeexxxxppppeeeecccctttt calls read() which can be interrupted by signals.  If
  518.      you define signal handlers, you can choose to restart or abort eeeexxxxppppeeeecccctttt's
  519.      internal read.  The variable, eeeexxxxpppp____rrrreeeeaaaaddddiiiinnnngggg, is true iff eeeexxxxppppeeeecccctttt's read has
  520.      been interrupted.  longjmp(exp_readenv,EXP_ABORT) will abort the read.
  521.      longjmp(exp_readenv,EXP_RESTART) will restart the read.
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  533.  
  534.  
  535.  
  536. LLLLOOOOGGGGGGGGIIIINNNNGGGG
  537.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____lllloooogggguuuusssseeeerrrr;;;;
  538.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____llllooooggggffffiiiilllleeee____aaaallllllll
  539.      eeeexxxxtttteeeerrrrnnnn FFFFIIIILLLLEEEE ****eeeexxxxpppp____llllooooggggffffiiiilllleeee;;;;
  540.  
  541.      If eeeexxxxpppp____lllloooogggguuuusssseeeerrrr is nonzero, eeeexxxxppppeeeecccctttt sends any output from the spawned
  542.      process to stdout.  Since interactive programs typically echo their
  543.      input, this usually suffices to show both sides of the conversation.  If
  544.      eeeexxxxpppp____llllooooggggffffiiiilllleeee is also nonzero, this same output is written to the stream
  545.      defined by eeeexxxxpppp____llllooooggggffffiiiilllleeee.  If eeeexxxxpppp____llllooooggggffffiiiilllleeee____aaaallllllll is non-zero, eeeexxxxpppp____llllooooggggffffiiiilllleeee is
  546.      written regardless of the value of eeeexxxxpppp____lllloooogggguuuusssseeeerrrr.
  547.  
  548.  
  549. DDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG
  550.      While I consider the library to be easy to use, I think that the
  551.      standalone expect program is much, much, easier to use than working with
  552.      the C compiler and its usual edit, compile, debug cycle.  Unlike typical
  553.      C programs, most of the debugging isn't getting the C compiler to accept
  554.      your programs - rather, it is getting the dialogue correct.  Also,
  555.      translating scripts from expect to C is usually not necessary.  For
  556.      example, the speed of interactive dialogues is virtually never an issue.
  557.      So please try the standalone 'expect' program first.  I suspect it is a
  558.      more appropriate solution for most people than the library.
  559.  
  560.      Nonetheless, if you feel compelled to debug in C, here are some tools to
  561.      help you.
  562.  
  563.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg;;;;
  564.      eeeexxxxtttteeeerrrrnnnn FFFFIIIILLLLEEEE ****eeeexxxxpppp____ddddeeeebbbbuuuuggggffffiiiilllleeee;;;;
  565.  
  566.      While expect dialogues seem very intuitive, trying to codify them in a
  567.      program can reveal many surprises in a program's interface.  Therefore a
  568.      variety of debugging aids are available.  They are controlled by the
  569.      above variables, all 0 by default.
  570.  
  571.      Debugging information internal to eeeexxxxppppeeeecccctttt is sent to stderr when
  572.      eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg is non-zero.  The debugging information includes every
  573.      character received, and every attempt made to match the current input
  574.      against the patterns.  In addition, non-printable characters are
  575.      translated to a printable form.  For example, a control-C appears as a
  576.      caret followed by a C.  If eeeexxxxpppp____llllooooggggffffiiiilllleeee is non-zero, this information is
  577.      also written to that stream.
  578.  
  579.      If eeeexxxxpppp____ddddeeeebbbbuuuuggggffffiiiilllleeee is non-zero, all normal and debugging information is
  580.      written to that stream, regardless of the value of eeeexxxxpppp____iiiissss____ddddeeeebbbbuuuuggggggggiiiinnnngggg.
  581.  
  582. CCCCAAAAVVVVEEEEAAAATTTTSSSS
  583.      The stream versions of the eeeexxxxppppeeeecccctttt functions are much slower than the file
  584.      descriptor versions because there is no way to portably read an unknown
  585.      number of bytes without the potential of timing out.  Thus, characters
  586.      are read one at a time.  You are therefore strongly encouraged to use the
  587.      file descriptor versions of eeeexxxxppppeeeecccctttt (although, automated versions of
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  599.  
  600.  
  601.  
  602.      interactive programs don't usually demand high speed anyway).
  603.  
  604.      You can actually get the best of both worlds, writing with the usual
  605.      stream functions and reading with the file descriptor versions of eeeexxxxppppeeeecccctttt
  606.      as long as you don't attempt to intermix other stream input functions
  607.      (e.g., fgetc).  To do this, pass fileno(stream) as the file descriptor
  608.      each time.  Fortunately, there is little reason to use anything but the
  609.      eeeexxxxppppeeeecccctttt functions when reading from interactive programs.
  610.  
  611.      There is no matching exp_pclose to exp_popen (unlike popen and pclose).
  612.      It only takes two functions to close down a connection (fclose() followed
  613.      by waiting on the pid), but it is not uncommon to separate these two
  614.      actions by large time intervals, so the function seems of little value.
  615.  
  616.      If you are running on a Cray running Unicos (all I know for sure from
  617.      experience), you must run your compiled program as root or setuid.  The
  618.      problem is that the Cray only allows root processes to open ptys. You
  619.      should observe as much precautions as possible:  If you don't need
  620.      permissions, setuid(0) only immediately before calling one of the spawn
  621.      functions and immediately set it back afterwards.
  622.  
  623.      Normally, ssssppppaaaawwwwnnnn takes little time to execute.  If you notice spawn taking
  624.      a significant amount of time, it is probably encountering ptys that are
  625.      wedged.  A number of tests are run on ptys to avoid entanglements with
  626.      errant processes.  (These take 10 seconds per wedged pty.)  Running
  627.      expect with the -d option will show if eeeexxxxppppeeeecccctttt is encountering many ptys
  628.      in odd states.  If you cannot kill the processes to which these ptys are
  629.      attached, your only recourse may be to reboot.
  630.  
  631. BBBBUUUUGGGGSSSS
  632.      The eeeexxxxpppp____ffffeeeexxxxppppeeeecccctttt functions don't work at all under HP-UX - it appears to
  633.      be a bug in getc.  Follow the advice (above) about using the eeeexxxxpppp____eeeexxxxppppeeeecccctttt
  634.      functions (which doesn't need to call getc).  If you fix the problem
  635.      (before I do - please check the latest release) let me know.
  636.  
  637. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  638.      An alternative to this library is the eeeexxxxppppeeeecccctttt program.  eeeexxxxppppeeeecccctttt interprets
  639.      scripts written in a high-level language which direct the dialogue.  In
  640.      addition, the user can take control and interact directly when desired.
  641.      If it is not absolutely necessary to write your own C program, it is much
  642.      easier to use eeeexxxxppppeeeecccctttt to perform the entire interaction.  It is described
  643.      further in the following references:
  644.  
  645.      "_e_x_p_e_c_t: _C_u_r_i_n_g _T_h_o_s_e _U_n_c_o_n_t_r_o_l_l_a_b_l_e _F_i_t_s _o_f _I_n_t_e_r_a_c_t_i_v_i_t_y" by Don Libes,
  646.      Proceedings of the Summer 1990 USENIX Conference, Anaheim, California,
  647.      June 11-15, 1990.
  648.  
  649.      "_U_s_i_n_g _e_x_p_e_c_t _t_o _A_u_t_o_m_a_t_e _S_y_s_t_e_m _A_d_m_i_n_i_s_t_r_a_t_i_o_n _T_a_s_k_s" by Don Libes,
  650.      Proceedings of the 1990 USENIX Large Installation Systems Administration
  651.      Conference, Colorado Springs, Colorado, October 17-19, 1990.
  652.  
  653.  
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))                                                      EEEEXXXXPPPPEEEECCCCTTTT((((3333TTTTccccllll))))
  665.  
  666.  
  667.  
  668.      expect(1), alarm(3), read(2), write(2), fdopen(3), execve(2), execvp(3),
  669.      longjmp(3), pty(4).
  670.  
  671.      There are several examples C programs in the test directory of eeeexxxxppppeeeecccctttt's
  672.      source distribution which use the expect library.
  673.  
  674. AAAAUUUUTTTTHHHHOOOORRRR
  675.      Don Libes, libes@nist.gov, National Institute of Standards and Technology
  676.  
  677. AAAACCCCKKKKNNNNOOOOWWWWLLLLEEEEDDDDGGGGEEEEMMMMEEEENNNNTTTTSSSS
  678.      Thanks to John Ousterhout (UCBerkeley) for supplying the pattern matcher.
  679.  
  680.      Design and implementation of the eeeexxxxppppeeeecccctttt library was paid for by the U.S.
  681.      government and is therefore in the public domain.  However the author and
  682.      NIST would like credit if this program and documentation or portions of
  683.      them are used.
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.